from django.db import models
from django.utils.timezone import now
from django.conf import settings
from blog.models import Article


# Create your models here.
class Comment(models.Model):
    cid = models.AutoField(primary_key=True)
    content = models.TextField('正文', max_length=300)
    updatedAt = models.DateTimeField('更新时间', default=now)
    author = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name='作者',
        on_delete=models.CASCADE
    )
    article = models.ForeignKey(
        Article,
        verbose_name='文章',
        on_delete=models.CASCADE
    )
    parentComment = models.ForeignKey(
        'self',
        verbose_name="上级评论",
        blank=True,
        null=True,
        on_delete=models.CASCADE
    )

    class Meta:
        ordering = ['cid']
        verbose_name = "评论"
        verbose_name_plural = verbose_name
        get_latest_by = 'cid'

    def __str__(self):
        return self.content
